﻿using System;
using System.Diagnostics;
using System.Globalization;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Newtonsoft.Json.Linq;
using WeiboPlus.Models;
using WeiboPlus.Service;

namespace WeiboPlus.Sina
{
    public class SinaJTokenToCountMapping : MappingBase<JToken, SNSCounts>
    {
        public SinaJTokenToCountMapping(IMappingFactory factory)
            : base(factory)
        {

        }

        public override SNSCounts Map(JToken s)
        {
            try
            {
                var count = new SNSCounts();

                if (s.SelectToken("cmt") != null)
                    count.Comments = (int)s.SelectToken("cmt");

                if (s.SelectToken("follower") != null)
                    count.Followers = (int)s.SelectToken("follower");

                if (s.SelectToken("status") != null)
                    count.Status = (int)s.SelectToken("status");

                if (s.SelectToken("dm") != null)
                    count.PrivateMessage = (int)s.SelectToken("dm");

                if (s.SelectToken("mention_status") != null)
                    count.Mentions = (int)s.SelectToken("mention_status");

                if (s.SelectToken("id") != null)
                    count.StatusId = (long)s.SelectToken("id");

                if (s.SelectToken("rt") != null)
                    count.Mentions = (int)s.SelectToken("rt");

                return count;

            }
            catch (Exception ex)
            {
                Debug.WriteLine(ex);
                return null;
                //throw;
            }

            //throw new NotImplementedException();
        }
    }
}
